﻿using UnityEngine.EventSystems;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;

public class UIHoverListener :MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{

    public static UIHoverListener RegHoverEvent(GameObject obj,Action<PointerEventData> enter, Action<PointerEventData> exit)
    {
        UIHoverListener uil = obj.GetComponent<UIHoverListener>();
        if (uil == null)
        {
            uil = obj.AddComponent<UIHoverListener>();
        }
        uil.enterEvent = enter;
        uil.exitEvent = exit;
        return uil;
    }
    Action<PointerEventData> enterEvent;
    Action<PointerEventData> exitEvent;
    void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData)
    {
        if (enterEvent != null)
        {
            enterEvent(eventData);
        }
    }

    void IPointerExitHandler.OnPointerExit(PointerEventData eventData)
    {
        if (exitEvent != null)
        {
            exitEvent(eventData);
        }
    }
}
